define(function(require, exports, module) {
  var common = require('common');
  var app = {
    layouts: {
      sidebar: require('main/admin/layouts/sidebar/view'),
      footer: require('main/admin/layouts/footer/view'),
      content: require('main/admin/layouts/content/view')
    },
    main: {
      example: require('main/admin/example/list'),
      todo: require('main/admin/todos/list'),
      ucenter: {
        password: require('main/admin/ucenter/password')
      },
      timesheet: require('main/admin/timesheet/list')
    }
  };
  module.exports = Backbone.Router.extend({
    routes: {
      '': 'index',
      'example': 'exampleList',
      'todo': 'todoList',
      'ucenter/password': 'resetPassword',
      'timesheet/:id': 'timesheet'
    },
    currentApp: null,
    initialize: function() {
      this.navbar = app.layouts.sidebar();
      this.footer = app.layouts.footer();
    },
    index: function() {
      this.todoList();
    },
    exampleList: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.layouts.content({
        viewData: common.example.header,
        ContentView: app.main.example
      });
    },
    todoList: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.layouts.content({
        viewData: common.todo.header,
        ContentView: app.main.todo
      });
    },
    resetPassword: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.layouts.content({
        viewData: common.ucenter.password.header,
        ContentView: app.main.ucenter.password
      });
    },
    timesheet: function(id) {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.layouts.content({
        rel: id,
        viewData: {},
        ContentView: app.main.timesheet
      });
    }
  });
});